#ifndef ARRAY_H
#define ARRAY_H

#include <stddef.h>
#include <visibility.h>

// a stupid like-a-vector container for stl-disabled environment
template <typename T>
class __EXPORT Array {
public:
	Array(int capacity) 
		: capacity_(capacity)
		, buffer_(new T[capacity])
		, size_(0)
	{}

	~Array() {
		delete[] buffer_;
		buffer_ = NULL;
	}

	int getSize() const {
		return size_;
	}

	bool isEmpty() const {
		return size_ == 0;
	}

	T& operator[](int index) {
		return buffer_[index];
	}

	const T& operator[](int index) const {
		return buffer_[index];
	}

	void push(const T &value) {
		if (size_ >= capacity_)
			expand();
		buffer_[size_++] = value;
	}

	void erase() {
		size_ = 0;
	}

private:
	Array();

	void expand() {
		capacity_ *= 2;
		T *buf = new T[capacity_];

		for (int i = 0; i < size_; ++i)
			buf[i] = buffer_[i];

		delete[] buffer_;
		buffer_ = buf;
	}

	int capacity_;
	T *buffer_;
	int size_;
};


#endif
